using History;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
    private DIALOGUE.DialogueSystem ds;
    private PlayerInput input;
    private List<(InputAction action, Action<InputAction.CallbackContext> command)> actions = new List<(InputAction action, Action<InputAction.CallbackContext> command)>();
    // Start is called before the first frame update
    private void Awake()
    {
        ds = DIALOGUE.DialogueSystem.instance;
        input = GetComponent<PlayerInput>();
        InitializedActions();
    }

    private void InitializedActions()
    {

        actions.Add((input.actions["Next"], PlayerPrompt));
        actions.Add((input.actions["HistoryBack"], OnHistoryBack));
        actions.Add((input.actions["HistoryForward"], OnHistoryForward));
        actions.Add((input.actions["HistoryLogs"], OnHistoryToggleLog));
    }

    private void OnEnable()
    {
        foreach(var inputAction in actions)
            inputAction.action.performed += inputAction.command;
    }

    private void OnDisable()
    {
        foreach (var inputAction in actions)
            inputAction.action.performed -= inputAction.command;
    }

    public void PlayerPrompt(InputAction.CallbackContext c)
    {
        ds.NotifyUserPrompt();
    }

    public void OnHistoryBack(InputAction.CallbackContext c)
    {
        HistoryManager.instance.GoBack();
    }
    public void OnHistoryForward(InputAction.CallbackContext c)
    {
        HistoryManager.instance.GoForward();
    }


    public void OnHistoryToggleLog(InputAction.CallbackContext c)
    {
        var logs = HistoryManager.instance.logManager;
        if (!logs.isOpen)
            HistoryManager.instance.logManager.Open();
        else
            HistoryManager.instance.logManager.Close();
    }
}
